<?php
$this->breadcrumbs=array();

$this->sidebarTop = array(
    'label' => Yii::t('BackEnd', 'Menu'),
    'link' => Yii::app()->createUrl('menu/admin')
);

Lvc::setCache('menu_parent_id_cache'.$menu->id,$menu->id,3600);
$this->moduleName = "menuItem";
$this->menu=array(
	array('label'=>Common::icon('delete'), 'itemOptions'=>array('style'=>'cursor:pointer', 'onclick'=>'Chienlv.deleteAll("form-admin", "menuItem/deleteAll?mId='.$menu->id.'");return false;')),
	array('label'=>Common::icon('create'), 'url'=>array('create')),
);

$this->slidebar = Backend::getModuleSlideBar('Setting', '/menuItem/admin');

Yii::app()->clientScript->registerScript('search', "
    $('.search-button').click(function(){
        $('.search-form').toggle();
        return false;
    });
    $('.search-form form').submit(function(){
        $.fn.yiiGridView.update('menu-item-grid', {
            data: $(this).serialize()
        });
        return false;
    });
");

$this->title = Common::icon('manager'). Yii::t('BackEnd',"menu item");
?>

<div class="search-form">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div>

<!--Use for ajax link-->


<?php echo CHtml::beginForm('#', 'post', array('id'=>'form-admin', 'name'=>'frmAdmin')); ?>
    <input type="hidden" id="moduleName" value="menuItem"/>
    <?php $this->widget('application.widgets.admin.GridView', array(
        'id'=>'menu-item-grid',
        'dataProvider'=>$model->search(),
        'columns'=>array(
            'id',
            array(
            'name' => 'name',
            'header' => Yii::t('BackEnd', 'Name'),
            'type' => 'raw',
            'htmlOptions' => array('style'=>'text-align: left;'),
            ),
            array(
                'name' => 'parent_id',
                'header'=> Yii::t('BackEnd', 'Parent item'),
                'value' => 'MenuItem::model()->findByPk($data->parent_id)->name',
            ),
            array(
            'name' => 'link',
            'header' => Yii::t('BackEnd', 'Link'),
            'type' => 'raw',
            'htmlOptions' => array('style'=>'text-align: left;'),
            ),
            'description:html',
            array(
            'name' => 'status',
            'header' => Yii::t('BackEnd', 'Status'),
            'type' => 'raw',
            'value' => '($data->status == MenuItem::STATUS_ENABLED)?CHtml::image(Yii::app()->request->baseUrl."/css/admin/images/tick.png", "enabled", array("class"=>"icon-status", "name"=>$data->id)):CHtml::image(Yii::app()->request->baseUrl."/css/admin/images/publish_x.png", "disabled", array("class"=>"icon-status", "name"=>$data->id))',
            'htmlOptions' => array('style'=>'text-align: center;'),
            ),
            array(
                'type'=>'raw',
                'value'=>'CHtml::hiddenField("ids[]", $data->id, array("id"=>"item-".$data->id)).CHtml::textField("sorder[]", $data->sorder, array("id"=>"sorder-".$data->id, "size"=>"4", "class"=>"numbersOnly"));',
                'name'=>'sorder',
                'header'=>Yii::t('BackEnd', 'Sort order').' '.CHtml::image(Yii::app()->request->baseUrl.'/css/admin/images/save.png', 'icon-save', array('style'=>'vertical-align: middle;cursor:pointer;', 'onclick'=>'javascript: $(this).parent().click(function(){return false;});document.frmAdmin.submit();return false;')),
                'htmlOptions'=>array('style'=>'text-align:center'),
            ),
            array(
                'class'=>'CButtonColumn',
                'header'=> Yii::t('BackEnd', 'Actions'),
                'viewButtonImageUrl'=> Yii::app()->request->baseUrl.'/css/admin/images/page-view.png',
                'updateButtonImageUrl'=> Yii::app()->request->baseUrl.'/css/admin/images/page-edit.png',
                'deleteButtonImageUrl'=> Yii::app()->request->baseUrl.'/css/admin/images/page-delete.png',
                'deleteConfirmation'=>Yii::t('BackEnd', 'Are you sure you want to delete this item?'),
            ),
        ),
    )); ?>
<?php echo CHtml::endForm(); ?>